<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>身体指数BMI测试</h1>
<form action="">
    <input type="text" name="height" placeholder="身高(米)">
    <input type="text" name="weight" placeholder="体重(公斤)">
    <input type="button" value="测试" @click="f()">
    <h2>测试结果:{{info}}</h2>
</form>
<!--引入CDN服务器的框架文件-->
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script src="https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/vue/2.6.14/vue.js"></script>

<script>
    let v = new Vue({
        el: "form",
        data: {
            info: "无"
        },
        methods: {
            f: function () {
                let data = new FormData(document.querySelector("form"));
                axios.post("/bmi", data).then(function (response) {
                    switch (response.data) {
                        case 1:
                            v.info = "太瘦了";
                            break;
                        case 2:
                            v.info = "正常";
                            break;
                        case 3:
                            v.info = "微微胖";
                            break;
                        case 4:
                            v.info = "微胖";
                            break;
                    }
                })
            }
        }
    })
</script>

</body>
</html>